<template xmlns="http://www.w3.org/1999/html">
  <h1>EL-表单组件</h1>
  <el-form style="width: 600px;margin: 0 auto;" label-width="80px">
    <el-form-item label="用户名">
      <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input placeholder="请输入密码" show-password v-model="user.password"></el-input>
    </el-form-item>
    <!-- 性别单选框居中 -->
    <el-form-item label="性别">
      <el-radio-group v-model="user.gender">
        <el-radio label="男" value="1"></el-radio>
        <el-radio label="女" value="0"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="城市">
      <el-select placeholder="请选择城市" v-model="user.city">
        <el-option label="上海" value="sh"></el-option>
        <el-option label="北京" value="bj"></el-option>
        <el-option label="广州" value="gz"></el-option>
        <el-option label="深圳" value="sz"></el-option>
      </el-select>
    </el-form-item>
    <!-- 管理员开关居中 -->
    <el-form-item label="管理员">
      <el-switch v-model="user.isShow"></el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="reg">点我提交</el-button>
    </el-form-item>
    <p v-if="isShow">按钮控制p标签是否渲染</p>
    <p v-show="isShow">按钮控制p标签是否可见</p>
    <el-form style=" width: 600px;margin: 0 auto;">
      <el-form-item>
        <el-button @click="controller">控制</el-button>
      </el-form-item>
      <el-form-item>
        <h3>按钮控制img标签是否渲染</h3>
        <input type="text" placeholder="请输入图片地址" v-model="img">
        <!--https://obs.yinruifei.com/upload/banner/20250922-1/6d8f92984ff035b69f1492d8881a30a2.png?x-image-process=image/quality,q_65/format,webp-->
        <img :src="img" alt="无效的链接">
      </el-form-item>
      <el-form-item>
        <ul>
          <li v-for="(a, index) in arr">
            {{a}}
            <el-button type="danger" @click="del(index)">删除</el-button>
          </li>
        </ul>
      </el-form-item>
    </el-form>
  </el-form>
</template>


<script setup>
import {ref} from "vue";

const user = ref ({
  username: 'cyhr',
  password: '123123',
  gender: '1',
  city: 'zz',
  isShow: true
});
//定义用户注册方法
const reg = () => {
  console.log(user)
}

const isShow = ref(true);

function controller() {
  isShow.value = !isShow.value;
}
const img = ref('');

const arr = ref([
  '1',
  '2',
  '3',
  '4',
  '5',
]);

const del = (index) => {
  arr.value.splice(index, 1);
}
</script>


<style scoped>

</style>
